﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FeedReader.Shared.Data;
using System.Xml;

namespace FeedReader.Shared.Extensions.OPML
{
    public static class OPMLExtensions
    {
        public static OPMLItem ParseItem(this OPMLItem theitem, XmlNode innernode)
        {
            OPMLItem item = new OPMLItem();
            item.Categories = new List<string>();
            if (innernode.ChildNodes.Count >= 1)
            {
                if (innernode.FirstChild.Attributes.Count > 1)
                {
                    item.Title = innernode.FirstChild.Attributes.GetNamedItem("title").InnerText;
                    item.Text = innernode.FirstChild.Attributes.GetNamedItem("text").InnerText;
                    item.Type = innernode.FirstChild.Attributes.GetNamedItem("type").InnerText;
                    item.RssURL = innernode.FirstChild.Attributes.GetNamedItem("xmlUrl").InnerText;
                    item.htmlURL = innernode.FirstChild.Attributes.GetNamedItem("htmlUrl").InnerText;
                    //item.Categories.Add(category);

                }
            }
            else
            {
                if (innernode.Attributes.Count > 1)
                {
                    item.Title = innernode.Attributes.GetNamedItem("title").InnerText;
                    item.Text = innernode.Attributes.GetNamedItem("text").InnerText;
                    item.Type = innernode.Attributes.GetNamedItem("type").InnerText;
                    item.RssURL = innernode.Attributes.GetNamedItem("xmlUrl").InnerText;
                    item.htmlURL = innernode.Attributes.GetNamedItem("htmlUrl").InnerText;
                    //item.Categories.Add(category);

                }
            }
            return item;
        }

    }
}
